<?php
/* tblStaff */
class tblStaff extends NocForm
	{
		protected $_ID                 = array();
		protected $_FirstName                 = array();
		protected $_Surname                 = array();
		protected $_Title                 = array();
		protected $_Address1                 = array();
		protected $_Address2                 = array();
		protected $_City                 = array();
		protected $_Region                 = array();
		protected $_PostalCode                 = array();
		protected $_Country                 = array();
		protected $_Phone                 = array();
		protected $_Fax                 = array();
		protected $_Email                 = array();
		protected $_Password                 = array();

		function __construct()
		{
			parent::__construct();
			$this->getRow();
		}
		public function get_ID()
		{
				return  $this->_get_IDValue();
		}

		private function _get_IDValue()
		{
			if(isset($this->_ID['value']))
				return $this->_ID['value'];
			else
				return false;
		}

		public function get_FirstName()
		{
				return  $this->_get_FirstNameValue();
		}

		private function _get_FirstNameValue()
		{
			if(isset($this->_FirstName['value']))
				return $this->_FirstName['value'];
			else
				return false;
		}

		public function get_Surname()
		{
				return  $this->_get_SurnameValue();
		}

		private function _get_SurnameValue()
		{
			if(isset($this->_Surname['value']))
				return $this->_Surname['value'];
			else
				return false;
		}

		public function get_Title()
		{
				return  $this->_get_TitleValue();
		}

		private function _get_TitleValue()
		{
			if(isset($this->_Title['value']))
				return $this->_Title['value'];
			else
				return false;
		}

		public function get_Address1()
		{
				return  $this->_get_Address1Value();
		}

		private function _get_Address1Value()
		{
			if(isset($this->_Address1['value']))
				return $this->_Address1['value'];
			else
				return false;
		}

		public function get_Address2()
		{
				return  $this->_get_Address2Value();
		}

		private function _get_Address2Value()
		{
			if(isset($this->_Address2['value']))
				return $this->_Address2['value'];
			else
				return false;
		}

		public function get_City()
		{
				return  $this->_get_CityValue();
		}

		private function _get_CityValue()
		{
			if(isset($this->_City['value']))
				return $this->_City['value'];
			else
				return false;
		}

		public function get_Region()
		{
				return  $this->_get_RegionValue();
		}

		private function _get_RegionValue()
		{
			if(isset($this->_Region['value']))
				return $this->_Region['value'];
			else
				return false;
		}

		public function get_PostalCode()
		{
				return  $this->_get_PostalCodeValue();
		}

		private function _get_PostalCodeValue()
		{
			if(isset($this->_PostalCode['value']))
				return $this->_PostalCode['value'];
			else
				return false;
		}

		public function get_Country()
		{
				return  $this->_get_CountryValue();
		}

		private function _get_CountryValue()
		{
			if(isset($this->_Country['value']))
				return $this->_Country['value'];
			else
				return false;
		}

		public function get_Phone()
		{
				return  $this->_get_PhoneValue();
		}

		private function _get_PhoneValue()
		{
			if(isset($this->_Phone['value']))
				return $this->_Phone['value'];
			else
				return false;
		}

		public function get_Fax()
		{
				return  $this->_get_FaxValue();
		}

		private function _get_FaxValue()
		{
			if(isset($this->_Fax['value']))
				return $this->_Fax['value'];
			else
				return false;
		}

		public function get_Email()
		{
				return  $this->_get_EmailValue();
		}

		private function _get_EmailValue()
		{
			if(isset($this->_Email['value']))
				return $this->_Email['value'];
			else
				return false;
		}

		public function get_Password()
		{
				return  $this->_get_PasswordValue();
		}

		private function _get_PasswordValue()
		{
			if(isset($this->_Password['value']))
				return $this->_Password['value'];
			else
				return false;
		}


		public function set_IDValue($strID)
		{
			if($this->validateInput("validatexxxxx", $strID, "ID "))
					return($this->_setNewValue($this->_ID, $strID));
			else
					return false;
		}

		public function set_FirstNameValue($strFirstName)
		{
			if($this->validateInput("validatexxxxx", $strFirstName, "FirstName "))
					return($this->_setNewValue($this->_FirstName, $strFirstName));
			else
					return false;
		}

		public function set_SurnameValue($strSurname)
		{
			if($this->validateInput("validatexxxxx", $strSurname, "Surname "))
					return($this->_setNewValue($this->_Surname, $strSurname));
			else
					return false;
		}

		public function set_TitleValue($strTitle)
		{
			if($this->validateInput("validatexxxxx", $strTitle, "Title "))
					return($this->_setNewValue($this->_Title, $strTitle));
			else
					return false;
		}

		public function set_Address1Value($strAddress1)
		{
			if($this->validateInput("validatexxxxx", $strAddress1, "Address1 "))
					return($this->_setNewValue($this->_Address1, $strAddress1));
			else
					return false;
		}

		public function set_Address2Value($strAddress2)
		{
			if($this->validateInput("validatexxxxx", $strAddress2, "Address2 "))
					return($this->_setNewValue($this->_Address2, $strAddress2));
			else
					return false;
		}

		public function set_CityValue($strCity)
		{
			if($this->validateInput("validatexxxxx", $strCity, "City "))
					return($this->_setNewValue($this->_City, $strCity));
			else
					return false;
		}

		public function set_RegionValue($strRegion)
		{
			if($this->validateInput("validatexxxxx", $strRegion, "Region "))
					return($this->_setNewValue($this->_Region, $strRegion));
			else
					return false;
		}

		public function set_PostalCodeValue($strPostalCode)
		{
			if($this->validateInput("validatexxxxx", $strPostalCode, "PostalCode "))
					return($this->_setNewValue($this->_PostalCode, $strPostalCode));
			else
					return false;
		}

		public function set_CountryValue($strCountry)
		{
			if($this->validateInput("validatexxxxx", $strCountry, "Country "))
					return($this->_setNewValue($this->_Country, $strCountry));
			else
					return false;
		}

		public function set_PhoneValue($strPhone)
		{
			if($this->validateInput("validatexxxxx", $strPhone, "Phone "))
					return($this->_setNewValue($this->_Phone, $strPhone));
			else
					return false;
		}

		public function set_FaxValue($strFax)
		{
			if($this->validateInput("validatexxxxx", $strFax, "Fax "))
					return($this->_setNewValue($this->_Fax, $strFax));
			else
					return false;
		}

		public function set_EmailValue($strEmail)
		{
			if($this->validateInput("validatexxxxx", $strEmail, "Email "))
					return($this->_setNewValue($this->_Email, $strEmail));
			else
					return false;
		}

		public function set_PasswordValue($strPassword)
		{
			if($this->validateInput("validatexxxxx", $strPassword, "Password "))
					return($this->_setNewValue($this->_Password, $strPassword));
			else
					return false;
		}
		public function update()
		{
			if($this->_boFailedValidation)
					return false;
					$strErrorMsg = "";
					$strSuccessMsg = "";
			if($this->get_ID() == "")
					return $this->_setFailScreens("Update aborted no record selected.", true);

			$strJoin = "";
			$strSql = "UPDATE tblStaff
					SET ";
					if($this->_ID['updated'])
					{
						$strSql .= $strJoin." ID = '".$this->_ID['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_ID['oldvalue']."' to '".$this->_ID['value']."'<br/>";
						$strErrorMsg .= "ID not updated<br/>";					}

					if($this->_FirstName['updated'])
					{
						$strSql .= $strJoin." FirstName = '".$this->_FirstName['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_FirstName['oldvalue']."' to '".$this->_FirstName['value']."'<br/>";
						$strErrorMsg .= "FirstName not updated<br/>";					}

					if($this->_Surname['updated'])
					{
						$strSql .= $strJoin." Surname = '".$this->_Surname['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Surname['oldvalue']."' to '".$this->_Surname['value']."'<br/>";
						$strErrorMsg .= "Surname not updated<br/>";					}

					if($this->_Title['updated'])
					{
						$strSql .= $strJoin." Title = '".$this->_Title['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Title['oldvalue']."' to '".$this->_Title['value']."'<br/>";
						$strErrorMsg .= "Title not updated<br/>";					}

					if($this->_Address1['updated'])
					{
						$strSql .= $strJoin." Address1 = '".$this->_Address1['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Address1['oldvalue']."' to '".$this->_Address1['value']."'<br/>";
						$strErrorMsg .= "Address1 not updated<br/>";					}

					if($this->_Address2['updated'])
					{
						$strSql .= $strJoin." Address2 = '".$this->_Address2['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Address2['oldvalue']."' to '".$this->_Address2['value']."'<br/>";
						$strErrorMsg .= "Address2 not updated<br/>";					}

					if($this->_City['updated'])
					{
						$strSql .= $strJoin." City = '".$this->_City['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_City['oldvalue']."' to '".$this->_City['value']."'<br/>";
						$strErrorMsg .= "City not updated<br/>";					}

					if($this->_Region['updated'])
					{
						$strSql .= $strJoin." Region = '".$this->_Region['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Region['oldvalue']."' to '".$this->_Region['value']."'<br/>";
						$strErrorMsg .= "Region not updated<br/>";					}

					if($this->_PostalCode['updated'])
					{
						$strSql .= $strJoin." PostalCode = '".$this->_PostalCode['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_PostalCode['oldvalue']."' to '".$this->_PostalCode['value']."'<br/>";
						$strErrorMsg .= "PostalCode not updated<br/>";					}

					if($this->_Country['updated'])
					{
						$strSql .= $strJoin." Country = '".$this->_Country['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Country['oldvalue']."' to '".$this->_Country['value']."'<br/>";
						$strErrorMsg .= "Country not updated<br/>";					}

					if($this->_Phone['updated'])
					{
						$strSql .= $strJoin." Phone = '".$this->_Phone['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Phone['oldvalue']."' to '".$this->_Phone['value']."'<br/>";
						$strErrorMsg .= "Phone not updated<br/>";					}

					if($this->_Fax['updated'])
					{
						$strSql .= $strJoin." Fax = '".$this->_Fax['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Fax['oldvalue']."' to '".$this->_Fax['value']."'<br/>";
						$strErrorMsg .= "Fax not updated<br/>";					}

					if($this->_Email['updated'])
					{
						$strSql .= $strJoin." Email = '".$this->_Email['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Email['oldvalue']."' to '".$this->_Email['value']."'<br/>";
						$strErrorMsg .= "Email not updated<br/>";					}

					if($this->_Password['updated'])
					{
						$strSql .= $strJoin." Password = '".$this->_Password['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Password['oldvalue']."' to '".$this->_Password['value']."'<br/>";
						$strErrorMsg .= "Password not updated<br/>";					}

			$strSql .= "WHERE ID = ". $this->get_ID();
			//Only execute sql if there is something to update.
			if($strJoin == ",")
			{
				//echo nl2br($strSql);
				if(!($DatabaseResult = mysql_query($strSql)))
					return $this->_setFailScreens($strErrorMsg);
				$GLOBALS['arrSuccessMessages'][] = $strSuccessMsg;
			}else
				$GLOBALS['arrSuccessMessages'][] = "No data hasn't changed so no updates made.";
			return(TRUE);
		}
			public function delete_tblStaff()
			{
				if($this->get_IDValue() == "")
					return $this->_setFailScreens("Delete aborted no record selected.", true);
				
		
				/* Deleted port forward from agg */
				$strSql =   "DELETE FROM tblStaff
		   					  WHERE ID		= ".$this->get_IDValue();
		
				$qryDeletetblStaff = new MySqlResults($strSql);
		
				if(!$qryDeletetblStaff->result)
					return ($this->_setFailScreens("An error occurred while trying to delete database entry."));
		
		
				$GLOBALS['arrSuccessMessages'][] = " has been removed";
				return true;
			}
		public function insert_tblStaff()
		{
			/* Check that all required fields have been set */
			if (!($this->_validateAllFieldsSet()))
			{
				return ($this->_setFailScreens("Fields required to add a new record haven't all been set", true));
			}
			
			$strSql =   "INSERT INTO tblStaff
						  (
		 	FirstName

		, 	Surname

		, 	Title

		, 	Address1

		, 	Address2

		, 	City

		, 	Region

		, 	PostalCode

		, 	Country

		, 	Phone

		, 	Fax

		, 	Email

		, 	Password
)VALUE(
		 	$this->get_FirstNameValue() 
		, 	$this->get_SurnameValue() 
		, 	$this->get_TitleValue() 
		, 	$this->get_Address1Value() 
		, 	$this->get_Address2Value() 
		, 	$this->get_CityValue() 
		, 	$this->get_RegionValue() 
		, 	$this->get_PostalCodeValue() 
		, 	$this->get_CountryValue() 
		, 	$this->get_PhoneValue() 
		, 	$this->get_FaxValue() 
		, 	$this->get_EmailValue() 
		, 	$this->get_PasswordValue() 
			)";
			
			$qryInserttblStaff = new MySqlResults($strSql);
		if ($qryInserttblStaff->result)
		{
			/*Extra post sql processing  */
		}else
			return $this->_setFailScreens("Unable to add to  tblStaff");
			
		return true;
	}
	}

?>